package com.demo.redis.controller;

import cn.hutool.core.util.StrUtil;
import com.demo.redis.service.UserService;
import com.demo.redis.utils.RedisUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author peter
 * @date 2021/11/21 上午13:22
 */
@RestController
@Slf4j
@RequestMapping("/request")
public class LockController {

    @Autowired
    UserService userService;

    @GetMapping("/lock")
    /**
     * 重复请求，上锁期间不允许
     */
    public String lock() {
        return userService.lock();
    }


    @GetMapping("/wornglock")
    /**
     * 上锁姿势不正确
     * 多次尝试会释放其他线程的锁
     */
    public String wornglock() {
        return userService.wronglock();
    }

    @GetMapping("/rightlock")
    /**
     * 上锁姿势不正确
     * 多次尝试会释放其他线程的锁
     */
    public String rightlock() {
        return userService.rightlock();
    }
}
